package com.jasperframework.boot.common.modules.redisson.service.monitor;

import com.alibaba.fastjson.JSONObject;
import com.jasperframework.boot.common.constant.JasperConstants;
import com.jasperframework.boot.common.modules.redisson.dao.base.StringRedisBaseDao;
import com.jasperframework.boot.common.modules.redisson.model.osi.OsiSystemBean;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>  </p>
 *
 * @author daizhao
 * @site https://miliqkdoc.motopa.cn/
 * @date 2022/12/12 12:12
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class OsiRedisService {

    private final StringRedisBaseDao stringRedisBaseDao;

    public void add(OsiSystemBean osiSystemBean) {
        if (osiSystemBean == null) return;
        stringRedisBaseDao.addItem(JasperConstants.OSI_SYSTEM_KEY, JSONObject.toJSONString(osiSystemBean));
    }

    public OsiSystemBean get() {
        String result = stringRedisBaseDao.getItem(JasperConstants.OSI_SYSTEM_KEY);
        return JSONObject.parseObject(result, OsiSystemBean.class);
    }

}
